﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESF.General.GUI;
using ESF.WinForms.Dialogs;
using ESF.General.MVP;
using ESF.General;

#endregion


namespace ESF.WinForms.Elements
{
	public class BaseUserControl : UserControl, IBaseViewer
	{
		#region Miembros

		protected IProgressDialog<IWin32Window> ProgressDialog;

		#endregion


		#region Constructor

		public BaseUserControl () : base ()
		{
			ProgressDialog = new ProgressDialog ();
			ProgressDialog.OnCancel += CancelCurrentOperation;
		}

		#endregion



		#region Miembros de IBaseViewer

		public bool frmEnabled
		{
			set { Enabled = value; }
		}
		

		public string frmErrorMsg
		{
			set { WinFormsHelper.ShowError (this, value); }
		}
		
		
		public string frmInfoMsg
		{
			set { WinFormsHelper.ShowInfo (this, value); }
		}
		
		
		public string frmOKMsg
		{
			set { WinFormsHelper.ShowInfo (this, value); }
		}


		public string frmWarnMsg
		{
			set
			{
				WinFormsHelper.ShowInfo(this, value);
			}
		}
		

		public string frmUserHostAddress
		{
			get 
			{
				return Log.UserHostAddress;
			}
		}

		// TODO: Soportar un modulo de autenticacion sobre windows
		public bool frmIsAuthenticated
		{
			get { return false; }
		}
		
		
		public string frmUserAlias
		{
			get { return "TODO"; }
		}

		public string frmApplicationCode
		{
			get { return ReadConfig.ApplicationCode; }
		}

		public string frmApplicationName
		{
			get { return ReadConfig.ApplicationName; }
		}


		public int CurrentAdvance100 { set { ProgressDialog.PercentageAdvance100 = value; } }

		public string CurrentStepName { set { ProgressDialog.CurrentStepName = value; } }

		#endregion
		
		
		#region Funciones
		
		protected virtual void CancelCurrentOperation () {}


		protected virtual void Clear () {}
		
		
		public void ShowClearProgressDialog ()
		{
			
		}


		public void LogError (Exception pEx)
		{
			Invoke ((Action) delegate () { ProgressDialog.Hide (); });

			Log.Error (pEx);
			
			frmErrorMsg = pEx.Message;
		}


		public void CloseApplication()
		{
			Application.Exit();
		}

		#endregion
	}
}
